package Algorithm.SearchAlgorithmDome;

import java.util.Scanner;

/**
 * ClassName:BasicSearch002
 * Package:Algorithm.SearchAlgorithmDome
 * Description:
 *
 * @Author:ZhangXin
 * @Create2023/2/3-14:12
 * @Version:v1.0
 */
public class BasicSearch002 {
    /*
     * 需求：定义一个方法利用基本查找,查询某个元素是否存在
     * 要求：不需要考虑数组中的元素重复
     * */
    public static void main(String[] args) {
        int[] arr = {131, 127, 147, 81, 103, 23, 7, 79};
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入你想要查找的数据：");
        int number = sc.nextInt();
        int index = BasicSearch(arr, number);
        if (index>=0){
            System.out.println("你想要查找的数据在数组中的"+index+"索引上");
        }else {
            System.out.println("没有你想要查找的数据!");
        }

    }
    public static int BasicSearch(int [] arr,int number){
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] == number){
                return i;
            }
        }
        return -1;
    }
}
